package collection_job;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class IteratorDemo {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        System.out.println(c);
        Iterator it = c.iterator();
        while (it.hasNext()) {
            String str = (String) it.next();
            System.out.println(str);
            if ("four".equals(str)) {
                it.remove();
            }
        }
        System.out.println(c);
        for (Object obj : c) {//元素类型 变量名：集合或数组
            String str = (String) obj;
            System.out.println(str);

        }
    }
}